//
//  baojiaview.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/21.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "baojiaview.h"

#import "UIImageView+WebCache.h"

@interface baojiaview ()
{
    UIScrollView *mainScroll;
    UILabel *labelNumber;
    UILabel *labelDetail;
    UILabel *labelDetailContent;
    UIView *backView;
    UIView *viewBottom;
    UIScrollView *imageScroll;
    
   
}

@end

@implementation baojiaview

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        mainScroll = [[UIScrollView alloc]initWithFrame:self.bounds];
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:mainScroll];
     
        _buttonCheck = [[UIButton alloc]init];
        _buttonCheck.frame = CGRectMake(0, 0,40, 40);
        [_imageView addSubview:_buttonCheck];
        
        UILabel*baojia = [[UILabel alloc]initWithFrame:CGRectMake(15,  10, 50, 16)];
        baojia.text = [NSString stringWithFormat:@"%@",@"报价"];
        baojia.font=[UIFont systemFontOfSize:16];
        baojia.textColor = [UIColor blackColor];
        [mainScroll addSubview:baojia];
        
        _itemPrice = [[UILabel alloc]initWithFrame:CGRectMake(baojia.right+5,  10, ScreenWidth, 16)];
        _itemPrice.text = [NSString stringWithFormat:@"¥%@",@"1000"];
        _itemPrice.font=[UIFont systemFontOfSize:16];
        _itemPrice.textColor = hongsecolor;
        [mainScroll addSubview:_itemPrice];
        
        _labeltime = [[UILabel alloc]initWithFrame:CGRectMake(15,  33, ScreenWidth, 15)];
        _labeltime.text = [NSString stringWithFormat:@"%@",@"广东深圳  2015-20-1"];
        _labeltime.textColor = zhonghuiColor;
        _labeltime.font=[UIFont systemFontOfSize:13];
        [mainScroll addSubview:_labeltime];
        
        _baojia = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-100,  0, 80, 50)];
        _baojia.text = [NSString stringWithFormat:@"%@",@""];
        _baojia.textColor = zhonghuiColor;
        _baojia.textAlignment=NSTextAlignmentRight;
        _baojia.font=[UIFont systemFontOfSize:16];
        [mainScroll addSubview:_baojia];
        
        
        UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(15, 55, ScreenWidth-30, 0.35)];
        line.backgroundColor=labelColor;
        [mainScroll addSubview:line];
        
        
        _textV=[[UILabel alloc]initWithFrame:CGRectMake(15, 65, ScreenWidth-30, 40)];
        
        
        
        [mainScroll addSubview:_textV];
        //滚动图片
        imageScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(15, _textV.bottom, ScreenWidth-40 , 85)];
        [mainScroll addSubview:imageScroll];
        
        imageScroll.contentSize = CGSizeMake(95 * _arrayImage.count, 85);
        imageScroll.pagingEnabled = YES;
        imageScroll.delegate = self;
        imageScroll.showsHorizontalScrollIndicator = NO;
        UILabel*line11=[[UILabel alloc]initWithFrame:CGRectMake(15, imageScroll.bottom+10, ScreenWidth-30, 0.35)];
        line11.backgroundColor=labelColor;
        [mainScroll addSubview:line11];
        
        
        

        _shuoming = [[UILabel alloc]initWithFrame:CGRectMake(15, line11.bottom+30, 260, 17)];
        _shuoming.text = @"说明";
        _shuoming.font=[UIFont systemFontOfSize:16];
        _shuoming.textColor = [UIColor blackColor];
        [mainScroll addSubview:_shuoming];
        
        
        
        
        _detail = [[UILabel alloc]initWithFrame:CGRectMake(15,  _shuoming.bottom+10, ScreenWidth-40, 15)];
        _detail.font=[UIFont systemFontOfSize:15];
        _detail.numberOfLines=0;
        _detail.textColor = [UIColor grayColor];
        [mainScroll addSubview:_detail];
        
        
        mainScroll.contentSize = CGSizeMake(ScreenWidth, _detail.bottom);
    }
    return self;
}

- (void)setArrayImage:(NSArray *)arrayImage
{
    _arrayImage = arrayImage;
    NSLog(@"---%@",_arrayImage);
    for (int i=0; i<_arrayImage.count; i++) {
        UIImageView *imageVC = [[UIImageView alloc]init];
        [imageVC setImageWithURL:[NSURL URLWithString:_arrayImage[i]] placeholderImage:[UIImage imageNamed:nil]];
        imageVC.frame = CGRectMake(95*i, 0, 85, 85);
        [imageScroll addSubview:imageVC];
    }
    imageScroll.contentSize = CGSizeMake(95 * _arrayImage.count, 85);
    labelNumber.text = [NSString stringWithFormat:@"%d/%lu",1,(unsigned long)_arrayImage.count];
}

- (void)setContent:(NSString *)content
{
    NSString *string = [NSString stringWithFormat:@"%@",content];
    CGSize size = [string sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:CGSizeMake(ScreenWidth, 1000)];
    labelDetailContent.text = string;
    labelDetailContent.frame = CGRectMake(5, labelDetail.bottom+5, ScreenWidth - 10, size.height);
    _imageView.frame = CGRectMake(0, labelDetailContent.bottom + 5, ScreenWidth, 150);
    backView.frame = CGRectMake(5, _imageView.bottom + 10, ScreenWidth - 10, 70);
    viewBottom.frame = CGRectMake(0, backView.bottom + 10, ScreenWidth, 50);
    mainScroll.contentSize = CGSizeMake(ScreenWidth, viewBottom.bottom);
    _buttonTap.frame = _imageView.bounds;
}


- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    int contentOffsetX = scrollView.contentOffset.x;
    labelNumber.text = [NSString stringWithFormat:@"%d/%lu",contentOffsetX/200+1,(unsigned long)_arrayImage.count];
}



@end
